package com.zxy.study.ui.opengl;

import android.content.Context;
import android.content.res.Resources;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/*
 *  @项目名：  study
 *  @包名：    com.zxy.study.ui.opengl
 *  @文件名:   TextResourceReader
 *  @创建者:   zhangxy
 *  @创建时间:  2019/8/12 11:41
 *  @描述：    TODO
 */
public class TextResourceReader {

	public static String readTextFileFromResource(Context context, int resourceId) {
		StringBuilder body = new StringBuilder();

		try {
			InputStream is = context.getResources().openRawResource(resourceId);
			InputStreamReader reader = new InputStreamReader(is);
			BufferedReader bufferedReader = new BufferedReader(reader);

			String nextLine;
			while ((nextLine = bufferedReader.readLine()) != null) {
				body.append(nextLine);
				body.append("\n");
			}

		} catch (IOException e) {
			e.printStackTrace();
		} catch (Resources.NotFoundException nfe) {
			nfe.printStackTrace();
		}

		return body.toString();
	}


}
